package cn.jobstart.service.impl;

import cn.jobstart.dao.ICompanyDao;
import cn.jobstart.es.RsOperationFlagEnum;
import cn.jobstart.es.listener.event.CompanyEsEvent;
import cn.jobstart.es.service.ICompanyEsService;
import cn.jobstart.modelExt.CompanyExt;
import cn.jobstart.pubInter.AbstractBaseService;
import cn.jobstart.pubInter.IBaseDao;
import cn.jobstart.pubInter.exception.SkException;
import cn.jobstart.searchExt.CompanySearchExt;
import cn.jobstart.service.ICompanyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * @author sunke
 * @Date 2023-09-06 15:00:20
 * @description CompanyService      企业
 */
@Service(value = "companyService")
@Slf4j
public class CompanyServiceImpl extends AbstractBaseService<CompanyExt, CompanySearchExt, String> implements ICompanyService {

    @Resource(name = "companyDao")
    private ICompanyDao companyDao;


    @Resource
    private ICompanyEsService companyEsService;


    @Override
    public IBaseDao<CompanyExt, CompanySearchExt, String> getDao() {
        return companyDao;
    }


    @Override
    public void afterInsert(CompanyExt obj) throws SkException {
        super.afterInsert(obj);
        CompanyEsEvent event = new CompanyEsEvent();
        event.setType(RsOperationFlagEnum.ADD.getTypeFlag());
        event.setCompanyId(obj.getId());
        companyEsService.publishEvent(event);
    }

    @Override
    public void afterUpdate(CompanyExt obj) throws SkException {
        super.afterUpdate(obj);
        CompanyEsEvent event = new CompanyEsEvent();
        event.setType(RsOperationFlagEnum.UPDATE.getTypeFlag());
        event.setCompanyId(obj.getId());
        companyEsService.publishEvent(event);
    }


    @Override
    public void afterDelete(String id) throws SkException {
        super.afterDelete(id);
        CompanyEsEvent event = new CompanyEsEvent();
        event.setType(RsOperationFlagEnum.DELETE.getTypeFlag());
        event.setCompanyId(id);
        companyEsService.publishEvent(event);
    }

    @Override
    public void afterLogicDelete(String id) throws SkException {
        super.afterLogicDelete(id);
        CompanyEsEvent event = new CompanyEsEvent();
        event.setType(RsOperationFlagEnum.DELETE.getTypeFlag());
        event.setCompanyId(id);
        companyEsService.publishEvent(event);
    }
}